package com.example.demo.controller;

import com.example.demo.entity.LeaseTimeEntity;
import com.example.demo.service.LeasetimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller

public class LeasetimeController {

    @Autowired
    private LeasetimeService leasetimeService;

    //添加租赁时长的html
    @RequestMapping("addLeaseTimeHtml")
    public String  addLeaseTimeHtml(){
       return "leasetime-add";
    }

    //添加租赁时长的方法
    @RequestMapping("addleasetime")
    @ResponseBody
    public String  addLeasetime(LeaseTimeEntity leaseTime){
        int res= leasetimeService.insertLeasetime(leaseTime);
        if (res>0){
            return "1";
        }else {
            return "0";
        }
    }

    //显示租赁时长列表
    @RequestMapping("leasetimelist")
    public String leasetimelist(Model model) {

        List<LeaseTimeEntity> leaseTimeList = leasetimeService.queryLeasetimeAll();
        model.addAttribute("leaseTimeList",leaseTimeList);
        return "leasetime-list";

    }

    //根据id查看对应租赁时长详情
    @RequestMapping("leasetimebyid")
    public String leasetimebyid(int ltid,Model model) {

        LeaseTimeEntity leaseTimeEntity = leasetimeService.queryLeasetimeById(ltid);
        model.addAttribute("leasetime",leaseTimeEntity);
        return "leasetime-view";
    }

    //修改对应租赁时长的方法
    @RequestMapping("updateleasetime")
    @ResponseBody
    public String  updateleasetime(LeaseTimeEntity leaseTime){
        int res= leasetimeService.updateLeasetime(leaseTime);
        if (res>0){
            return "1";
        }else {
            return "0";
        }
    }

    //删除租赁时长的方法
    @RequestMapping("delleasetime")
    @ResponseBody
    public String  delleasetime(int ltid){
        int res= leasetimeService.deleteByIdLeasetime(ltid);
        if (res>0){
            return "1";
        }else {
            return "0";
        }
    }

}